// JavaScript Document


var logstyle = "0";
var gamescroll1 = new ScrollPic();
var gamescroll2 = new ScrollPic();
var tvscroll1 = new ScrollPic();
var tvscroll2 = new ScrollPic();
var catoscroll1 = new ScrollPic();
var catoscroll2 = new ScrollPic();
var activitycode = "";
var gamecode = "";
var flowcode = "";
var chuangcode = "";
var tvcode = "";
var catocode = "";
var brotype = "1";
var now;
var hour1;
var hour2;
var systype = "";
var flowcdiv = '<div id="flow"><div class="mainIcon"></div><div class="warnIcon"></div><div class="process"><div id="bgdiv"><div id="showdiv"></div></div></div></div><div style="border-bottom:2px dashed #999; width:90%; margin-left:5%;"></div><div id="call"><div class="mainIcon"></div><div class="warnIcon"></div><div class="process"><div id="bgdiv"><div id="showdiv"></div></div></div></div><div style="border-bottom:2px dashed #999; margin-left:5%; width:90%;"></div><div id="sms"><div class="mainIcon"></div><div class="warnIcon"></div><div class="process"><div id="bgdiv"><div id="showdiv"></div></div></div></div><div style="border-bottom:2px dashed #999; margin-left:5%; width:90%;"></div><div id="mms"><div class="mainIcon"></div><div class="warnIcon"></div><div class="process"><div id="bgdiv"><div id="showdiv"></div></div></div></div>';
$(document).ready(function (e) {
	now = new Date();
	hour1 = now.getHours();
	window.setInterval("clock()", 3601000);
	window.setTimeout("resize()", 5000);
	if (detectDeviceType() == "Apple") {
		$("#vieport").attr("content", "width=480,initial-scale=0.53, maximum-scale=0.53, minimum-scale=0.53,user-scalable=no");
		systype = "2";
	} else if (detectDeviceType() == "Android") {
		$("#vieport").attr("content", "width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no,target-densitydpi=300");
		systype = "1";
	} else if (detectDeviceType() == "winp") {
		systype = "3";
	} else {
		systype = "0";
	}
	
	getversionurl();
	var screenwidth = document.body.clientWidth;
	window.scrollTo(0, 1);
	type = getQueryParameter("type");
	if (type == "0") {
		brotype = "0";
	}
	var phone = getQueryParameter("phonenum");
	var key = getQueryParameter("userkey");
	if (phone != null && key != null && phone + key != "") {
		var url = jsonserver + "portal/relogin/" + phone + "/" + key;
		$.getJSON(url + ".jsonp?callback=?", {}, function (data) {
			if (data.flag == "1") {
				islogin = true;
				logstyle = "1";
				$("#login").hide();
				$("#logout").show();
				window.localStorage.setItem("phonenum", phone);
				window.localStorage.setItem("userkey", key);
				if(data.custName){
					window.localStorage.setItem("username", data.custName);
				}else{
					window.localStorage.setItem("username", phone);
				}
				window.localStorage.setItem("flowtype", data.custType);
				doSendUrl("http://www.wo.com?jumpUrl=&keyword=自动登录&moduleId=99&srcChannel=&currentUrl=" + location.href + "&mobilePhone=" + window.localStorage.getItem("phonenum"), "", "2");
				$("#user").text(window.localStorage.getItem("username"));
				
				getflowdet();
			}
		});
	} else {
		autologin("1");
	}
	if (window.localStorage.getItem("phonenum")) {
		if(window.localStorage.getItem("username")&&window.localStorage.getItem("username")!="null"){
			$("#user").text(window.localStorage.getItem("username"));
		}else{
			$("#user").text(window.localStorage.getItem("phonenum"));
		}
		//$("#user").text(window.localStorage.getItem("username")||window.localStorage.getItem("phonenum"));
		logstyle = "1";
		$("#login").hide();
		$("#logout").show();
	} else {
		var neturl = jsonserver + "portal/getSkeyUrl";
		$.getJSON(neturl + ".jsonp?callback=?", {}, function (data) {
			$("body").append('<img style="display:none" src=' + data.url + data.skey + ' />');
			var neturl2 = jsonserver + "portal/getPhone/" + data.skey;
			window.setTimeout(function () {
				$.getJSON(neturl2 + ".jsonp?callback=?", {}, function (data2) {
					if (data2.flag == "1") {
						window.localStorage.setItem("phonenum", data2.phoneNum);
						window.localStorage.setItem("userkey", data2.userkey);
						if(data2.custName){
							window.localStorage.setItem("username", data2.custName);
						}else{
							window.localStorage.setItem("username", data2.phoneNum);
						}
						window.localStorage.setItem("flowtype", data2.custType);
						$("#user").text(window.localStorage.getItem("username"));
						getflowdet();
						$("#login").hide();
						$("#logout").show();
					}
				});
			}, 2000);
		});
	}
	var weaurl = jsonserver2 + "wea/101010100";
	$.getJSON(weaurl + ".jsonp?callback=?", {}, function (data) {
		$("#weather").append('<table height="45px" border="0" cellpadding="0" cellspacing="0"><tr><td><img style="margin-top:10px;" src="' + data.weaImg + '"/>&nbsp;</td><td>' + data.cityName + " " + data.wendu + '</td></tr></table>');
	});
	var timeurl = jsonserver + "portal/date";
	$.getJSON(timeurl + ".jsonp?callback=?", {}, function (data) {
		$("#date").text(data.date);
	});
	var menuurl = jsonserver + "portal/modlist/i/" + brotype;
	
	$.getJSON(menuurl + ".jsonp?callback=?", {}, function (data) {
		if (_.where(data, {
				div_name : "activity"
			}) != "") {
			activitycode = _.first(_.where(data, {
						div_name : "activity"
					})).mod_code;
		}
		if (_.where(data, {
				div_name : "game"
			}) != "") {
			gamecode = _.first(_.where(data, {
						div_name : "game"
					})).mod_code;
		}
		if (_.where(data, {
				div_name : "flowcheck"
			}) != "") {
			flowcode = _.first(_.where(data, {
						div_name : "flowcheck"
					})).mod_code;
		}
		if (_.where(data, {
				div_name : "mobichuang"
			}) != "") {
			chuangcode = _.first(_.where(data, {
						div_name : "mobichuang"
					})).mod_code;
		}
		if (_.where(data, {
				div_name : "mbtv"
			}) != "") {
			tvcode = _.first(_.where(data, {
						div_name : "mbtv"
					})).mod_code;
		}
		if (_.where(data, {
				div_name : "carton"
			}) != "") {
			catocode = _.first(_.where(data, {
						div_name : "carton"
					})).mod_code;
		}
		
		var menutable = "";
		var indexarray = new Array();
		_.each(data, function (field, i) {
			if (field.div_name != "flowcheck") {
				indexarray.push($("#" + field.div_name));
			} else if (window.localStorage.getItem("flowtype") == "3G" || !window.localStorage.getItem("phonenum")) {
				indexarray.push($("#" + field.div_name));
			}
		});
		_.each(_.initial(data), function (field, i) {
			if ((i + 1) % 4 == 1) {
				menutable = menutable + '<tr align="center"><td align="center" width="25%"><div align="center" class="menubtn"><span id="menutab_' + field.mod_code + '" class="blog3" data-name=' + field.mod_desc + ' data-link=' + field.mod_link + '  data-mod="" onclick="">' + field.mod_desc + '</span></div></td>';
			} else if ((i + 1) % 4 == 0) {
				menutable = menutable + '<td align="center" width="25%"><div align="center" class="menubtn"><span id="menutab_' + field.mod_code + '" class="blog3" data-name=' + field.mod_desc + ' data-link=' + field.mod_link + '  data-mod="" onclick="">' + field.mod_desc + '</span></div></td></tr>';
			} else {
				menutable = menutable + '<td align="center" width="25%"><div  align="center" class="menubtn"><span id="menutab_' + field.mod_code + '" class="blog3" data-name=' + field.mod_desc + ' data-link=' + field.mod_link + '  data-mod="" onclick="">' + field.mod_desc + '</span></div></td>';
			}
		});
		var lastone = _.last(data);
		if (data.length % 4 == 1) {
			menutable = menutable + '<tr align="center" width="25%"><td align="center"><div align="center" class="menubtn"><span id="menutab_' + lastone.mod_code + '" class="blog3" data-name=' + lastone.mod_desc + ' data-link=' + lastone.mod_link + '  data-mod="" onclick="">' + lastone.mod_desc + '</span></div></td><td></td><td></td><td></td></tr>';
		} else {
			var blanktd = "";
			for(i=0;i<4-(data.length % 4);i++){
				blanktd = blanktd+'<td width="25%"></td>';
			}
			menutable = menutable + '<td align="center" width="25%"><div align="center" class="menubtn"><span id="menutab_' + lastone.mod_code + '" class="blog3" data-name=' + lastone.mod_desc + ' data-link=' + lastone.mod_link + '  data-mod="" onclick="">' + lastone.mod_desc + '</span></div></td>'+blanktd+'</tr>';
		}
		$("#menutab").append(menutable);
		$(".menubtn").live("touchstart",function(){
			$(this).attr("class","menubtn2");
		});
		$(".menubtn2").live("touchend",function(){
			$(this).attr("class","menubtn");
		});
		$("#all").empty();
		_.each(indexarray, function (field, i) {
			$("#all").append(field);
		});
		var acturl = jsonserver + "portal/activelist/i/" + brotype;
		$.getJSON(acturl + ".jsonp?callback=?", {}, function (data) {
			_.each(data, function (field, i) {
				$("#antivitystyle").text(field.ac_text);
				$("#activityimg").html('<img id="actimg" width="100%" src="" onclick="" />');
				$("#actimg").attr("src", field.advertisement.ad_icon);
				if (field.advertisement.ad_link.indexOf("?") == -1) {
					$("#actimg").attr({
						"data-name" : field.advertisement.ad_keyword,
						"data-link" : field.advertisement.ad_link + "?phonenum=" + window.localStorage.getItem("phonenum") + "&userkey=" + window.localStorage.getItem("userkey"),
						"class" : "blog"
					});
				} else {
					$("#actimg").attr({
						"data-name" : field.advertisement.ad_keyword,
						"data-link" : field.advertisement.ad_link + "&phonenum=" + window.localStorage.getItem("phonenum") + "&userkey=" + window.localStorage.getItem("userkey"),
						"class" : "blog"
					});
				}
				
				_.each(field.acList, function (txt, j) {
					$("#moreactivity").append('<div id="act_' + txt.acy_id + '" class="actlist blog3" data-name=' + txt.acy_keywords + ' data-link=' + txt.acy_link + '  data-mod="" onclick="">' + txt.acy_name + '</div>');
				});
			});
			$("#activity").find("*").attr("data-mod", "mod_" + activitycode);
		});
		
		var lukynumurl = jsonserver + "portal/luckynum";
		$.getJSON(lukynumurl + ".jsonp?callback=?", {}, function (data) {
			$("#activitydet").append(data.oth_data);
			var frameurl = $("#xingyunshuzi_link").attr("href");
			$("#xingyunshuzi_link").attr("href", frameurl + "&phonenum=" + window.localStorage.getItem("phonenum") + "&userkey=" + window.localStorage.getItem("userkey"));
		});
		var flowurl2 = jsonserver + "portal/flowlist/i/" + brotype + "/" + systype;
		$.getJSON(flowurl2 + ".jsonp?callback=?", {}, function (data) {
			var flowcoll = _.first(data);
			$("#flowbtn1").text(_.first(flowcoll.columnList).col_name);
			$("#flowbtn1").attr("data-name", _.first(flowcoll.columnList).col_name);
			$("#flowbtn2").text(_.last(flowcoll.columnList).col_name);
			$("#flowbtn2").attr("data-name", _.last(flowcoll.columnList).col_name);
			$("#gotocloud1").text(_.first(flowcoll.btnLinkList).text_name);
			$("#gotocloud1").attr({
				"data-name" : _.first(flowcoll.btnLinkList).text_name,
				"data-link" : _.first(flowcoll.btnLinkList).text_link
			});
			$("#cloudhref").attr({
				"data-name" : _.first(flowcoll.btnLinkList).text_name,
				"data-link" : _.first(flowcoll.btnLinkList).text_link
			});
			
			$("#gotocloud2").text(_.last(flowcoll.btnLinkList).text_name);
			$("#gotocloud2").attr({
				"data-name" : _.last(flowcoll.btnLinkList).text_name,
				"data-link" : _.last(flowcoll.btnLinkList).text_link
			});
			
			_.each(flowcoll.productInfoList, function (field, i) {
				if (i % 2 == 0) {
					listType = "a"
				} else {
					listType = "b"
				}
				appendapplist("applist", listType, field.p_id, field.p_icon, field.p_name, field.p_type, field.p_info, field.p_link);
				$("#appdl_" + field.p_id).attr("data-link", field.p_dwn_link);
			});
			$("#flowcheck").find("*").attr("data-mod", "mod_" + flowcode);
			//blog("flowcheck");
		});
		
		var gameurl = jsonserver + "portal/gamelist/i/" + brotype;
		$.getJSON(gameurl + ".jsonp?callback=?", {}, function (data) {
			var gamecoll = _.first(data);
			$("#gamebtn1").text(_.first(gamecoll.columnList).col_name);
			$("#gamebtn1").attr("data-name", _.first(gamecoll.columnList).col_name);
			$("#gamebtn2").text(_.last(gamecoll.columnList).col_name);
			$("#gamebtn2").attr("data-name", _.last(gamecoll.columnList).col_name);
			$("#gotoplay1").text(_.first(gamecoll.btnLinkList).text_name);
			$("#gotoplay1").attr({
				"data-name" : _.first(gamecoll.btnLinkList).text_name,
				"data-link" : _.first(gamecoll.btnLinkList).text_link
			});
			
			$("#gotoplay2").text(_.last(gamecoll.btnLinkList).text_name);
			$("#gotoplay2").attr({
				"data-name" : _.last(gamecoll.btnLinkList).text_name,
				"data-link" : _.last(gamecoll.btnLinkList).text_link
			});
			addimg("recogameimg", gamecoll.advertisement1);
			addimg("newgameimg", gamecoll.advertisement2);
			_.each(gamecoll.productsList1, function (field, i) {
				if (i % 2 == 0) {
					gameType1 = "a"
				} else {
					gameType1 = "b"
				}
				appendgamelist("recogamelist", gameType1, field.p_id, field.p_icon, field.p_name, field.p_grade, field.p_text, field.p_dwn_link, field.p_link)
			});
			_.each(gamecoll.productsList2, function (field, i) {
				if (i % 2 == 0) {
					gameType2 = "a"
				} else {
					gameType2 = "b"
				}
				appendgamelist("newgamelist", gameType2, field.p_id, field.p_icon, field.p_name, field.p_grade, field.p_text, field.p_dwn_link, field.p_link)
			});
			//滑动
			
			scrollimg(gamescroll1, "recogameimg", "recogamedot", screenwidth, screenwidth);
			$("#newgame").show();
			scrollimg(gamescroll2, "newgameimg", "newgamedot", screenwidth, screenwidth);
			$("#newgame").hide();
			$("#game").find("*").attr("data-mod", "mod_" + gamecode);
			//blog("game");
		});
		
		var tvurl = jsonserver + "portal/mobiletvlist/i/" + brotype;
		$.getJSON(tvurl + ".jsonp?callback=?", {}, function (data) {
			var tvcoll = _.first(data);
			$("#tvbtn1").text(_.first(tvcoll.columnList).col_name);
			$("#tvbtn1").attr("data-name", _.first(tvcoll.columnList).col_name);
			$("#tvbtn2").text(_.last(tvcoll.columnList).col_name);
			$("#tvbtn2").attr("data-name", _.last(tvcoll.columnList).col_name);
			$("#gotoview1").text(_.first(tvcoll.btnLinkList).text_name);
			$("#gotoview1").attr({
				"data-name" : _.first(tvcoll.btnLinkList).text_name,
				"data-link" : _.first(tvcoll.btnLinkList).text_link
			});
			
			$("#gotoview2").text(_.last(tvcoll.btnLinkList).text_name);
			$("#gotoview2").attr({
				"data-name" : _.last(tvcoll.btnLinkList).text_name,
				"data-link" : _.last(tvcoll.btnLinkList).text_link
			});
			
			addimg("jingcaitvimg", tvcoll.advertisement1);
			addimg("toptvimg", tvcoll.advertisement2);
			_.each(tvcoll.productsList1, function (field, i) {
				if (i % 2 == 0) {
					tvType1 = "a"
				} else {
					tvType1 = "b"
				}
				appendtvlist("jingcaitvlist", tvType1, field.p_id, field.p_icon, field.p_name, field.p_grade, field.p_text, field.p_dwn_link, field.p_link)
			});
			_.each(tvcoll.productsList2, function (field, i) {
				if (i % 2 == 0) {
					tvType2 = "a"
				} else {
					tvType2 = "b"
				}
				appendtvlist("toptvlist", tvType2, field.p_id, field.p_icon, field.p_name, field.p_grade, field.p_text, field.p_dwn_link, field.p_link)
			});
			//滑动
			
			scrollimg(tvscroll1, "jingcaitvimg", "jingcaitvdot", screenwidth, screenwidth);
			$("#renqipaihang").show();
			scrollimg(tvscroll2, "toptvimg", "toptvdot", screenwidth, screenwidth);
			$("#renqipaihang").hide();
			$("#mbtv").find("*").attr("data-mod", "mod_" + tvcode);
			//blog("mbtv");
		});
		
		var catourl = jsonserver + "portal/animationlist/i/" + brotype;
		$.getJSON(catourl + ".jsonp?callback=?", {}, function (data) {
			var catocoll = _.first(data);
			$("#catobtn1").text(_.first(catocoll.columnList).col_name);
			$("#catobtn1").attr("data-name", _.first(catocoll.columnList).col_name);
			$("#catobtn2").text(_.last(catocoll.columnList).col_name);
			$("#catobtn2").attr("data-name", _.last(catocoll.columnList).col_name);
			$("#gotolook1").text(_.first(catocoll.btnLinkList).text_name);
			$("#gotolook1").attr({
				"data-name" : _.first(catocoll.btnLinkList).text_name,
				"data-link" : _.first(catocoll.btnLinkList).text_link
			});
			
			$("#gotolook2").text(_.last(catocoll.btnLinkList).text_name);
			$("#gotolook2").attr({
				"data-name" : _.last(catocoll.btnLinkList).text_name,
				"data-link" : _.last(catocoll.btnLinkList).text_link
			});
			
			addimg("hottuijianimg", catocoll.advertisement1);
			addimg("autherimg", catocoll.advertisement2);
			_.each(catocoll.productsList1, function (field, i) {
				if (i % 2 == 0) {
					catoType1 = "a"
				} else {
					catoType1 = "b"
				}
				appendcatolist("hottuijianlist", catoType1, field.p_id, field.p_icon, field.p_name, field.p_grade, field.p_text, field.p_dwn_link, field.p_link)
			});
			_.each(catocoll.productsList2, function (field, i) {
				if (i % 2 == 0) {
					catoType2 = "a"
				} else {
					catoType2 = "b"
				}
				appendcatolist("autherlist", catoType2, field.p_id, field.p_icon, field.p_name, field.p_grade, field.p_text, field.p_dwn_link, field.p_link)
			});
			//滑动
			
			scrollimg(catoscroll1, "hottuijianimg", "hottuijiandot", screenwidth, screenwidth);
			$("#autherzhuanfang").show();
			scrollimg(catoscroll2, "autherimg", "autherdot", screenwidth, screenwidth);
			$("#autherzhuanfang").hide();
			$("#carton").find("*").attr("data-mod", "mod_" + catocode);
			//blog("carton");
		});
		
		var mobichuangurl = jsonserver + "portal/undertaking/i/" + brotype;
		$.getJSON(mobichuangurl + ".jsonp?callback=?", {}, function (data) {
			$("#chuangyeimg").html('<img id="chuangimg" width="100%" src=' + data.ad_icon + ' onclick="" />');
			$("#chuangimg").attr({
				"data-name" : data.ad_keyword,
				"class" : "blog3",
				"data-link" : data.ad_link
			});
			$("#chuangyetxt").html(data.recommended);
			$("#gotochuang").text(data.text_name);
			$("#gotochuang").attr("data-name", data.text_name);
			$("#gotochuang").attr("data-link", data.text_link);
			$("#gotochuang2").text(data.text_name);
			$("#gotochuang2").attr("data-name", data.text_name);
			$("#gotochuang2").attr("data-link", data.text_link);
			
			$("#namelist").append(data.commission_link);
			$("#mobichuang").find("*").attr("data-mod", "mod_" + chuangcode);
			//blog("mobichuang");
		});
		//$("#index").bind("mousedown",function(){
		//	$("#index").css("background-color","#999");
		//});
		//$("#index").bind("mouseup",function(){
		//	$("#index").css("background-color","#f3f3f3");
		//});
		$("#personbtn").bind("click", function () {
			if ($("#baibian").attr("class") == "baibian") {
				//$("#logsta").attr("class", "logsta2");
				$("#baibian").attr("class", "baibian2");
				//$("#personbtn").attr("class", "personbtn2");
				//$("#geren").css("color", "#ff8803");
				//$("#person").attr("src", "../img/icon_01.png");
				//$("#shuxian").toggle();
				//$("#blank").toggle();
				$("#menubottom").attr("class","menubottom2");
				$("#persondet").toggle();
				$("#logsanjiao").toggle();
				//$("#personbtn").width("214px");
				//$("#beforico").css("padding-left", "8px");
			} else {
				//$("#logsta").attr("class", "logsta");
				$("#baibian").attr("class", "baibian");
				//$("#personbtn").attr("class", "personbtn");
				//$("#geren").css("color", "#ff8803");
				//$("#person").attr("src", "../img/icon_01.png");
				//$("#shuxian").toggle();
				//$("#blank").toggle();
				$("#menubottom").attr("class","menubottom");
				$("#persondet").toggle();
				$("#logsanjiao").toggle();
				//$("#personbtn").width("206px");
				//$("#beforico").css("padding-left", "0px");
			}
		});
		$("#detupdown").bind("click", function () {
			$("#activitydet").toggle();
			if ($("#upordown").attr("src") == "../img/arrow_down.png") {
				$("#upordown").attr("src", "../img/arrow_up.png");
				$("#detupdown").addClass("blog");
				$("#viewornon").text("点击收起");
			} else {
				$("#upordown").attr("src", "../img/arrow_down.png");
				$("#detupdown").removeClass("blog");
				$("#viewornon").text("点击查看");
			}
		});
		$("#recosoft").bind("click", function () {
			$("#flowsanjiao").animate({
				left : "80%"
			}, "fast");
			$("#recosoft").attr("class", "title1");
			$("#yourflow").attr("class", "title2");
			$("#flowdet").hide();
			$("#recosoftdet").show();
			
		});
		$("#yourflow").bind("click", function () {
			$("#flowsanjiao").animate({
				left : "-60px"
			}, "fast");
			$("#yourflow").attr("class", "title1");
			$("#recosoft").attr("class", "title2");
			$("#recosoftdet").hide();
			$("#flowdet").show();
			
		});
		$("#newup").bind("click", function () {
			$("#gamesanjiao").animate({
				left : "80%"
			}, "fast");
			$("#newup").attr("class", "title1");
			$("#hotreco").attr("class", "title2");
			$("#recogame").hide();
			$("#newgame").show();
			
		});
		$("#hotreco").bind("click", function () {
			$("#gamesanjiao").animate({
				left : "-60px"
			}, "fast");
			$("#hotreco").attr("class", "title1");
			$("#newup").attr("class", "title2");
			$("#newgame").hide();
			$("#recogame").show();
			
		});
		//手机电视
		$("#renqitop").bind("click", function () {
			$("#tvsanjiao").animate({
				left : "80%"
			}, "fast");
			$("#renqitop").attr("class", "title1");
			$("#jingcaireco").attr("class", "title2");
			$("#jingcaituijian").hide();
			$("#renqipaihang").show();
			
		});
		$("#jingcaireco").bind("click", function () {
			$("#tvsanjiao").animate({
				left : "-60px"
			}, "fast");
			$("#jingcaireco").attr("class", "title1");
			$("#renqitop").attr("class", "title2");
			$("#renqipaihang").hide();
			$("#jingcaituijian").show();
			
		});
		//动漫
		$("#autheraq").bind("click", function () {
			$("#catosanjiao").animate({
				left : "80%"
			}, "fast");
			$("#autheraq").attr("class", "title1");
			$("#hotcatoreco").attr("class", "title2");
			$("#hottuijian").hide();
			$("#autherzhuanfang").show();
			
		});
		$("#hotcatoreco").bind("click", function () {
			$("#catosanjiao").animate({
				left : "-60px"
			}, "fast");
			$("#hotcatoreco").attr("class", "title1");
			$("#autheraq").attr("class", "title2");
			$("#autherzhuanfang").hide();
			$("#hottuijian").show();
			
		});
		/*
		$("#tonormal").bind("click",function(){
		doSendUrl("http://www.wo.com?jumpUrl="+normalurl+"&keyword="+$("#tonormal").attr("data-name")+"&moduleId=99&srcChannel=&currentUrl="+location.href+"&mobilePhone="+window.localStorage.getItem("phonenum"),normalurl,"1");
		});
		 */
		$("#tocolor").bind("click", function () {
			doSendUrl("http://www.wo.com?jumpUrl=" + colorurl + window.localStorage.getItem("phonenum") + "/" + window.localStorage.getItem("userkey") + "?1" + "&keyword=" + $("#tocolor").attr("data-name") + "&moduleId=99&srcChannel=&currentUrl=" + location.href + "&mobilePhone=" + window.localStorage.getItem("phonenum"), colorurl + window.localStorage.getItem("phonenum") + "/" + window.localStorage.getItem("userkey") + "?1", "2");
		});
		//流量
		//var u1="http://192.168.6.61:8580/mobile-html5-rest/bipb/userphone/18618457227/asfdasdfasdfasdf/portal";
		if (window.localStorage.getItem("phonenum") == null) {
			var u1 = jsonserver + "portal/queryNullFlow";
		} else {
			var u1 = jsonserver + "portal/flowById/" + window.localStorage.getItem("phonenum") + "/" + window.localStorage.getItem("userkey");
		}
		$.getJSON(u1 + ".jsonp?callback=?", {}, function (data) {
			if (data.sb.status == "00000") {
				$("yunguanjia1").html(flowcdiv);
				if (data.packageDesc != null) {
					$("#packtxt").text(data.packageDesc);
				} else {
					$("#packtxt").text("信息暂未获取");
				}
				if (data.curMonthFee != null) {
					$("#paymaonth").text(data.curMonthFee + "元");
				} else {
					$("#paymaonth").text("信息暂未获取");
				}
				if (data.monthCalcDate != null && data.monthCalcDate != "--") {
					$("#jiezhi").text(data.timeForDatas.split(" ")[0]);
					//$("#jiezhi").text(data.timeForDatas.substr(0, 4) + "-" + data.timeForDatas.substr(4, 2) + "-" + data.timeForDatas.substr(6, 2));
				} else if (data.monthCalcDate == "--") {
					$("#jiezhi").text(data.timeForDatas);
				} else {
					$("#jiezhi").text("信息暂未获取");
				}
				$.each(data.pblist, function (i, items) {
					switch (i) {
					case 0:
						initbar("call1", items);
						break;
					case 1:
						initbar("flow1", items);
						break;
					case 2:
						initbar("sms1", items);
						break;
					case 3:
						if (items.visibleFlag) {
							initbar("mms1", items);
						}
						break;
					}
					
				});
			} else {
				$("#nowpackage").css("text-align", "center");
				$("#nowpackage").html("信息暂未获取<br>请稍后再试");
				$("#huafei").hide();
				$("#yunguanjia").hide();
			}
			$("#flowcheck").find("*").attr("data-mod", "mod_" + flowcode);
			//blog("flowdet");
		});
		
		$("#gototop").bind("click", function () {
			window.scrollTo(0, 1);
		});
		
	});
	$("#activity").find("*").attr("data-mod", "mod_" + activitycode);
	//blog("bottom");
	//记录日志
	
	$(".blog").live("click", function () {
		var mainkey = $(this).attr("data-name");
		var gotourl = $(this).attr("data-link");
		var mod = $(this).attr("data-mod").split("_")[1];
		var come = "";
		var nowurl = location.href;
		var phone = window.localStorage.getItem("phonenum");
		doSendUrl("http://www.wo.com?jumpUrl=" + gotourl + "&keyword=" + mainkey + "&moduleId=" + mod + "&srcChannel=" + come + "&currentUrl=" + nowurl + "&mobilePhone=" + phone, gotourl, "2");
	});
	$(".blog3").live("click", function () {
		var mainkey = $(this).attr("data-name");
		var gotourl = $(this).attr("data-link");
		var mod = $(this).attr("data-mod").split("_")[1];
		var come = "";
		var nowurl = location.href;
		var phone = window.localStorage.getItem("phonenum");
		//TODO
		//if(gotourl)
		doSendUrl("http://www.wo.com?jumpUrl=" + gotourl + "&keyword=" + mainkey + "&moduleId=" + mod + "&srcChannel=" + come + "&currentUrl=" + nowurl + "&mobilePhone=" + phone, gotourl, "1");
	});
	
});
function appendgamelist(listId, listType, id, img, name, star, txt, pllink, iconlink) {
	var namewidth = document.body.clientWidth - 411;
	$("#" + listId).append('<div id="game_' + id + '" class="list' + listType + '" onclick=""><table width="100%" height="130px" border="0" cellpadding="0" cellspacing="0"><tr><td rowspan="2" width="136px" style="text-align:center"><img src=' + img + ' style="width:87px" class="blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + linktxt + ' data-mod=""/></td><td height="50px"><div style="width:' + namewidth + 'px" class="listname basictxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + name + '</div></td><td id="gamestar_' + id + '" class="liststar blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="" width="170px"></td><td rowspan="2" width="105px" class="listbtn"><a href="javascript:void(0)"><img id="gamepl_' + id + '" src="../img/paly.png" class="blog3" data-name=' + name + btntxt + ' data-link=' + pllink + ' data-mod="" onclick=""/></a></td></tr><tr><td colspan="2" class="dettxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + txt + '</td></tr></table></div>');
	for (i = 1; i <= star; i++) {
		$("#gamestar_" + id).append('<img src="../img/star_01.png"/>');
	}
	for (i = 1; i <= (5 - star); i++) {
		$("#gamestar_" + id).append('<img src="../img/star_02.png"/>');
	}
	
}

function appendapplist(listId, listType, id, img, name, type, txt, iconlink) {
	var namewidth = document.body.clientWidth - 408;
	$("#" + listId).append('<div id="app_' + id + '" class="list' + listType + '" onclick=""><table width="100%" height="130px" border="0" cellpadding="0" cellspacing="0"><tr><td rowspan="2" width="136px" style="text-align:center"><img src=' + img + ' style="width:87px" class="blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod=""/></td><td height="50px"><div style="width:' + namewidth + 'px" class="listname basictxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + name + '</div></td><td class="liststartxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="" width="167px" >' + type + '</td><td rowspan="2" width="105px" class="listbtn" onclick=""><a href="javascript:void(0)"><img id="appdl_' + id + '" class="blog3" data-name=' + name + btntxt + ' data-mod="" src="../img/download.png"/></a></td></tr><tr><td colspan="2" class="dettxt blog" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + txt + '</td></tr></table></div>');
}
function appendtvlist(listId, listType, id, img, name, star, txt, vlink, iconlink) {
	var namewidth = document.body.clientWidth - 241;
	$("#" + listId).append('<div id="tv' + id + '" class="list' + listType + '" onclick=""><table width="100%" height="130px" border="0" cellpadding="0" cellspacing="0"><tr><td rowspan="3" width="136px" style="text-align:center"><img src=' + img + ' style="height:87px; width:110px" class="blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod=""/></td><td><div style="width:' + namewidth + 'px" class="listname basictxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + name + '</div></td><td rowspan="3" width="105px" class="listbtn"><a href="javascript:void(0)"><img id="tvplay_' + id + '" src="../img/broadcast.png" class="blog3" data-name=' + name + btntxt + ' data-link=' + vlink + ' data-mod="" onclick=""/></a></td></tr><tr><td class="dettxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + txt + '</td></tr><tr><td class="blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="""><div id="tvstar_' + id + '" style="height:30px"></div></td></tr></table></div>');
	for (i = 1; i <= star; i++) {
		$("#tvstar_" + id).append('<img src="../img/star_01.png"/>');
	}
	for (i = 1; i <= (5 - star); i++) {
		$("#tvstar_" + id).append('<img src="../img/star_02.png"/>');
	}
	
}

function appendcatolist(listId, listType, id, img, name, star, txt, clink, iconlink) {
	var namewidth = document.body.clientWidth - 411;
	$("#" + listId).append('<div id="cato_' + id + '" class="list' + listType + '" onclick=""><table width="100%" height="130px" border="0" cellpadding="0" cellspacing="0"><tr><td rowspan="2" width="136px" style="text-align:center"><img src=' + img + ' style="width:87px" class="blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod=""/></td><td height="50px"><div style="width:' + namewidth + 'px" class="listname basictxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + name + '</div></td><td id="catostar_' + id + '" class="liststar blog3" width="170px" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod=""></td><td rowspan="2" width="105px" class="listbtn"><a href="javascript:void(0)"><img id="catolook_' + id + '" src="../img/read.png" class="blog3" data-name=' + name + btntxt + ' data-link=' + clink + ' data-mod="" onclick=""/></a></td></tr><tr><td colspan="2" class="dettxt blog3" data-name=' + name + linktxt + ' data-link=' + iconlink + ' data-mod="">' + txt + '</td></tr></table></div>');
	//下面模板引擎写法
	//var catodiv = _.template($("#cotodiv").html(),{listType:listType,id:id,img:img,name:name,txt:txt,clink:clink,iconlink:iconlink,namewidth:namewidth});
	//$("#"+listId).append(catodiv);
	for (i = 1; i <= star; i++) {
		$("#catostar_" + id).append('<img src="../img/star_01.png"/>');
	}
	for (i = 1; i <= (5 - star); i++) {
		$("#catostar_" + id).append('<img src="../img/star_02.png"/>');
	}
	
}
function resize() {
	var imgwidth = document.body.clientWidth;
	var namewidth1 = imgwidth - 408;
	var namewidth2 = imgwidth - 411;
	var namewidth3 = imgwidth - 241;
	$("#applist .listname").width(namewidth1 + "px");
	$("#game .listname").width(namewidth2 + "px");
	$("#carton .listname").width(namewidth2 + "px");
	$("#mbtv .listname").width(namewidth3 + "px");
	$(".bigimg img").width(imgwidth + "px");
	reloadpic(gamescroll1, imgwidth, "recogameimg")
	reloadpic(gamescroll2, imgwidth, "newgameimg")
	reloadpic(tvscroll1, imgwidth, "jingcaitvimg")
	reloadpic(tvscroll2, imgwidth, "toptvimg")
	reloadpic(catoscroll1, imgwidth, "hottuijianimg")
	reloadpic(catoscroll2, imgwidth, "autherimg")
	/*scrollimg("recogameimg","recogamedot",imgwidth,imgwidth);
	scrollimg("newgameimg","newgamedot",imgwidth,imgwidth);
	scrollimg("jingcaitvimg","jingcaitvdot",imgwidth,imgwidth);
	scrollimg("toptvimg","toptvdot",imgwidth,imgwidth);
	scrollimg("hottuijianimg","hottuijiandot",imgwidth,imgwidth);
	scrollimg("autherimg","autherdot",imgwidth,imgwidth);*/
	//$("[style='float: left; overflow: hidden;']").attr("style","overflow: hidden;");
	//recogameimg.pageWidth = imgwidth;
}
function addimg(frameid, imglist) {
	
	var screenwidth = document.body.scrollWidth;
	_.each(imglist, function (field, i) {
		$("#" + frameid).append('<img src=' + field.ad_icon + ' width="' + screenwidth + 'px" alt=' + field.ad_keyword + ' class="blog3" data-name=' + field.ad_keyword + ' data-link=' + field.ad_link + ' data-mod="" onclick="" />');
		//$("#"+frameid).append('<img src="../img/img_07.png" width="'+screenwidth+'px"/>');
	});
	//$("#"+frameid).append('<img src="../img/img_07.png" width="'+screenwidth+'px"/><img src="../img/img_07.png" width="'+screenwidth+'px"/><img src="../img/img_07.png" width="'+screenwidth+'px"/>');
	
}
function scrollimg(frame, divId, dotId, width, scrollwidth) {
	var img = new ScrollPic();
	frame.scrollContId = divId; //内容容器ID
	frame.dotListId = dotId; //点列表ID
	frame.dotOnClassName = "selected";
	frame.arrLeftId = "sl_left"; //左箭头ID
	frame.arrRightId = "sl_right"; //右箭头ID
	frame.frameWidth = width;
	frame.pageWidth = scrollwidth;
	frame.upright = false;
	frame.speed = 10;
	frame.space = 30;
	frame.initialize(); //初始化
}
/*
function logout(){
var outurl = jsonserver+"portal/loginOut";
$.getJSON(outurl+".jsonp?callback=?",{},function(data){
if(data.flag=="1"){
window.localStorage.clear();
logstyle = "0";
location.reload();
}
});
}
 */
function gotocheck(url) {
	if (window.localStorage.getItem("phonenum")) {
		var gotourl = url + ".html";
		var mod = $("#" + url).attr("data-mod").split("_")[1];
		var come = "";
		var mainkey = $("#" + url).attr("data-name");
		var nowurl = location.href;
		var phone = window.localStorage.getItem("phonenum");
		doSendUrl("http://www.wo.com?jumpUrl=" + gotourl + "&keyword=" + mainkey + "&moduleId=" + mod + "&srcChannel=" + come + "&currentUrl=" + nowurl + "&mobilePhone=" + phone, url + ".html", "2");
	} else {
		doSendUrl("http://www.wo.com?jumpUrl=" + gotourl + "&keyword=" + mainkey + "&moduleId=" + mod + "&srcChannel=" + come + "&currentUrl=" + nowurl + "&mobilePhone=", "login.html?page=" + url, "2");
	}
}
function reloadpic(img, imgwidth, divId) {
	//slide_01 为加载完JS以后定义为全局对象。多个需要在头部定义多个对象。
	try {
		img.frameWidth = imgwidth;
		img.pageWidth = imgwidth;
	} catch (ex) {}
	//针对样式表对象进行修改大小，可以为所有的滑动内容同时处理。
	$("#" + divId).width(imgwidth + "px");
	$("#" + divId + " .bigimg img").width(imgwidth + "px");
}
function blog(divname) {}
function clock() {
	now = new Date();
	hour2 = now.getHours();
	if (hour2 <= hour1) {
		window.location.reload();
	}
}
function getflowdet() {
	var u1 = jsonserver + "portal/flowById/" + window.localStorage.getItem("phonenum") + "/" + window.localStorage.getItem("userkey");
	$.getJSON(u1 + ".jsonp?callback=?", {}, function (data) {
		if (data.sb.status == "00000") {
			$("#yunguanjia1").hide();
			$("#yunguanjia2").show()
			$("yunguanjia2").html(flowcdiv);
			if (data.packageDesc != null) {
				$("#packtxt").text(data.packageDesc);
			} else {
				$("#packtxt").text("信息暂未获取");
			}
			if (data.curMonthFee != null) {
				$("#paymaonth").text(data.curMonthFee + "元");
			} else {
				$("#paymaonth").text("信息暂未获取");
			}
			if (data.monthCalcDate != null && data.monthCalcDate != "--") {
				$("#jiezhi").text(data.timeForDatas.substr(0, 4) + "-" + data.timeForDatas.substr(4, 2) + "-" + data.timeForDatas.substr(6, 2));
			} else if (data.monthCalcDate == "--") {
				$("#jiezhi").text(data.timeForDatas);
			} else {
				$("#jiezhi").text("信息暂未获取");
			}
			$.each(data.pblist, function (i, items) {
				switch (i) {
				case 0:
					initbar("call2", items);
					break;
				case 1:
					initbar("flow2", items);
					break;
				case 2:
					initbar("sms2", items);
					break;
				case 3:
					if (items.visibleFlag) {
						initbar("mms2", items);
					}
					break;
				}
				
			});
		} else {
			$("#nowpackage").css("text-align", "center");
			$("#nowpackage").html("信息暂未获取<br>请稍后再试");
			$("#huafei").hide();
			$("#yunguanjia").hide();
		}
		$("#flowcheck").find("*").attr("data-mod", "mod_" + flowcode);
		//blog("flowdet");
	});
}
